package org.elec.mac.ehcache;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.elec.mac.utils.DateUtil;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by Bean on 2017/5/13.
 */
@Component
public class TokenEhCache {

    /**
     *
     * @param username
     * @return
     */
    public String createToken(String username) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(DateUtil.formatDate(new Date(), DateUtil.DATE_TIME_PATTERN_1));
        buffer.append(username);
        buffer.append(RandomStringUtils.randomAlphanumeric(10));
        return DigestUtils.md5Hex(buffer.toString());
    }
}
